package edu.gatech.ealf.magiclenseplaf;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.plaf.ButtonUI;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TreeUI;
import javax.swing.tree.TreePath;

public class MLTreeUI extends TreeUI implements MouseListener {

    
    
    private ZoomHelper zoomer = null;
    
    public MLTreeUI() {
        super();
    }

    public static ComponentUI createUI(JComponent c) {
        return new MLTreeUI();
    }

    @Override
    public void installUI(JComponent c) {
        super.installUI(c);
        MagicLenseLookAndFeel.getInstance().registerComponentInstallation(this, c);
        zoomer = new ZoomHelper(c);
        c.addMouseListener(this);
    }

    public void paint(Graphics g, JComponent c) {
    }

    @Override
    public void uninstallUI(JComponent c) {
        super.uninstallUI(c);
        MagicLenseLookAndFeel.getInstance().registerComponentUninstallation(this, c);
        c.removeMouseListener(this);
        if(zoomer != null){
            zoomer.destroy();
        }
        zoomer = null;
    }

    @Override
    public void update(Graphics g, JComponent c) {
        paint(g, c);
    }

    public void mouseClicked(MouseEvent e) {
        if(e.getButton()== MouseEvent.BUTTON2){
            zoomer.toggleZoomable();
        }
    }


    public void mouseEntered(MouseEvent e) {
        //System.out.println("MLTreeUI.mouseEntered");
        zoomer.zoom();
    }

    public void mouseExited(MouseEvent e) {
        boolean hasFocus = zoomer.curComponent.hasFocus();
        zoomer.unZoom();
        if(hasFocus){
            zoomer.curComponent.requestFocusInWindow();
        }
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void cancelEditing(JTree tree) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public TreePath getClosestPathForLocation(JTree tree, int x, int y) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public TreePath getEditingPath(JTree tree) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Rectangle getPathBounds(JTree tree, TreePath path) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public TreePath getPathForRow(JTree tree, int row) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getRowCount(JTree tree) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getRowForPath(JTree tree, TreePath path) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public boolean isEditing(JTree tree) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void startEditingAtPath(JTree tree, TreePath path) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public boolean stopEditing(JTree tree) {
        // TODO Auto-generated method stub
        return false;
    }
}

